#include <bits/stdc++.h>
using namespace std;
int D, N;
const int maxd = 80, maxn = 5000+10;
int sum;
struct Node{
    int d, id;
    int l, r, p;
    bool operator < (const Node &u)const{return d > u.d;}
}V[maxn];

priority_queue<Node> leaf;
list<int> vacant[maxn];
int lower(){
    int k = (int)log2(N+1);
    int r = N-(1<<k)+1;
    return D < (r*k + (k-2)*(1<<(k-1)) + 1);
}

bool good(Node &u){
    int d = u.d - 2;
    return d>=0 && !vacant[d].empty();
}

bool move(int iu){
    Node &u = V[iu];
    if(!good(u)) return false;

    int iv = vacant[u.d - 2].front();
    Node& v = V[iv];
    Node& p = V[u.p];

    if(p.l && p.r) vacant[p.d].push_back(p.id);
    if(p.l == u.id) p.l = 0;
    else p.r = 0;
    if(p.l==0 && p.r==0 && good(p)) leaf.push(p);


    if(v.l==0) v.l = u.id;
    else v.r = u.id;
    if(v.l && v.r) vacant[v.d].pop_front();

    vacant[u.d].erase(find(vacant[u.d].begin(), vacant[u.d].end(), u.id));
    vacant[u.d-1].push_back(u.id);
    u.p = iv;
    --u.d; --sum;
    return true;
}

bool solve(){
    while(!leaf.empty()){
        int  iu = leaf.top().id; leaf.pop();
        bool can;
        do{
            if(sum == D) return true;
            can = move(iu);
        }while(can);
    }
    return false;
}

void init(){
    for(auto &i:vacant) i.clear();
    while(!leaf.empty()) leaf.pop();
    memset(V, 0, sizeof(V));
}

int main() {
    ios_base::sync_with_stdio(false);cin.tie(nullptr);
    int T; cin >> T;
    while(T--){
        init();
        cin >> N >> D;
        if(lower()) {cout <<"NO\n"; continue;}
        sum = N*(N-1)/2;
        if(sum < D) {cout <<"NO\n"; continue;}
        for(int i=1; i<=N; i++) {V[i].d = i-1; V[i].id = i;}
        for(int i=2; i<=N; ++i) V[i].p = i-1;
        for (int i = 1; i <= N-1; ++i) V[i].l = i+1;
        for (int d = 0; d <= N-1; ++d) vacant[d].push_back(d+1);

        leaf.push(V[N]);
        if(!solve()) cout <<"NO\n";
        else{
            cout << "YES\n";
            for (int i = 2; i <= N; ++i) {
                cout << V[i].p << " ";
            }
            cout << "\n";
        }

    }
    return 0;
}